<?php

/**
 * @package Framework03
 * @author Walter Tamboer
 */

/**
 * A singleton settings container.
 */
class Settings
{
	/**
	 * @var array An array with all settings.
	 */
	private $Data;
	/**
	 * Initialzies a new instance of this class.
	 */
	private function __construct()
	{
		$this->Data = array();
		$this->Data['debug'] = false;
	}
	/**
	 * Gets the instance of this class.
	 * @return Settings Returns the instance of this class.
	 */
	public static function Singleton()
	{
		static $Instance;

		if (!$Instance)
		{
			$Instance = new Settings();
		}

		return $Instance;
	}
	/**
	 * Gets a setting from the internal array.
	 * @param string $Name The name of the setting to get.
	 * @param mixed $DefaultValue The default value which is returned if the setting doesn't exist.
	 * @return mixed Returns the value of the requested setting.
	 */
	public function Get($Name, $DefaultValue = null)
	{
		$Name = strtolower($Name);

		if (isset($this->Data[$Name]))
			return $this->Data[$Name];
		else if (isset($this->Data['debug']) && $this->Data['debug'])
			throw new Exception('Trying to get the setting "' . $Name . '" which doesn\'t exist.', 404);

		return $DefaultValue;
	}
	/**
	 * Sets a setting with it's value.
	 * @param string $Name The name of the setting to set.
	 * @param string $Value The value of the setting to set.
	 */
	public function Set($Name, $Value)
	{
		$Name = strtolower($Name);
		
		$this->Data[$Name] = $Value;
	}
}

?>